#include "create_message_task.h"

#include "base/logging.h"
#include "im/common/common.h"
#include "im/adapters/presence_notifier_adapter.h"
#include "im/adapters/message_exchange_adapter.h"

namespace imserver {

CreateMessageTask::CreateMessageTask(const ImMessage & message) : message_(message) {
}

void CreateMessageTask::run() {
  int msg_type = MessageType(message_);
  if (msg_type == MSG_TYPE_TYPING) {
    int ret = PresenceNotifierAdapter::Instance().UserTyping(message_.sender, message_.receiver, 2);
    LOG_INFO("PresenceNotifierAdapter UserTyping s=" << message_.sender << " r=" << message_.receiver 
             << " ret=" << ret);
  } else if (msg_type == MSG_TYPE_TALK) {
    int ret = MessageExchangeAdapter::Instance().CreateMessage(message_, 2);
    LOG_INFO("MessageExchangeAdapter CreateMessage ret=" << ret);
  } else {
    LOG_WARN("CreateMessageTask bad message type=" << msg_type << " body=" << message_.body);
  }
}

}


